const express = require('express');
// const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();
const bodyParser = require('body-parser');
const controller = require('./controller');
const { log, getIPAdress } = require('./utils');

// 请求日志
app.use((req, res, next) => {
  log(`${Date.now()} ${req.method} ${req.url}`);
  next();
});

app.use(bodyParser.json());

app.use(controller('controllers'));

// controller中没有的地址
// app.use((req, res, next) => {
//   log(`转发地址${req.url}`);
//   // 可以根据正则进行转换
//   app.use('/', createProxyMiddleware({ target: 'http://127.0.0.1:7001', changeOrigin: true }));
//   next();
// });

app.listen(3000);
log(`${getIPAdress()}:3000`);
